<template>
	<div id="personnel">
		<el-row :gutter="20">
			<el-col :span="4">
				<el-input placeholder="请输入用户名" v-model="listQuery.userName" clearable></el-input>
			</el-col>
			<el-col :span="4">
				<el-input placeholder="请输入账号" v-model="listQuery.account" clearable></el-input>
			</el-col>

			<el-col :span="4">
				<el-select style="width: 100%" v-model="listQuery.type" clearable placeholder="请选择用户类型">
					<el-option v-for="(v, i) in typeData" :key="i" :label="v.label" :value="v.value"></el-option>
				</el-select>
			</el-col>
			<el-col :span="4">
				<el-select style="width: 100%" v-model="listQuery.roleIds" clearable placeholder="请选择角色">
					<el-option v-for="(v, i) in roleTableData" :key="i" :label="v.key" :value="v.value"></el-option>
				</el-select>
			</el-col>
			<el-col :span="4">
				<el-select style="width: 100%" v-model="listQuery.del" clearable placeholder="请选择用户状态">
					<el-option label="可用" :value="1"></el-option>
					<el-option label="禁用" :value="2"></el-option>
				</el-select>
			</el-col>
			<!-- <el-col :span="4" class="top_unit" style="position: relative">
        <el-popover placement="bottom-start" v-model="treeFlag1" class="orgTree" trigger="click">
          <el-tree
            :data="companyTableData"
            :props="defaultProps"
            :expand-on-click-node="false"
            node-key="id"
            style="width: 300px"
            @node-click="handleNodeClickDep1"
          ></el-tree>
          <el-input
            slot="reference"
            ref="input"
            v-model="treeName1"
            clearable
            :readonly="true"
            style="width: 100%"
            placeholder="请选择部门"
          ></el-input>
        </el-popover>
        <i @click.stop="closeName1" class="el-icon-circle-close" v-if="treeName1"></i>
        <i class="el-icon-arrow-down" v-else></i>
      </el-col> -->
			<el-col class="jurisdiction" :span="4">
				<el-button plain type="custom" @click="getList()">搜索</el-button>
			</el-col>
		</el-row>
		<el-row :gutter="20" style="margin-top: 10px">
			<el-col class="jurisdiction">
				<el-button type="custom" v-if="$button('738')" @click="showEditDialog('add')">新增用户</el-button>
			</el-col>
			<el-col class="jurisdiction">
				<el-button type="custom" plain v-if="$button('739')" @click="configRoles()">批量配置角色</el-button>
				<el-button type="custom" plain v-if="$button('739')" @click="configLevel()">批量配置资源权限</el-button>
			</el-col>
			<el-col class="jurisdiction">
				<el-button type="custom" plain v-if="$button('740')" @click="configDepts()">批量配置部门</el-button>
			</el-col>
			<!-- <el-col>
        <ImportButtons type="user" />
      </el-col> -->
		</el-row>
		<el-container>
			<el-aside width="280px" style="padding-top: 10px">
				<div class="aside-wrap">
					<!-- <p class="aside-title">
            显示子部门：
            <el-switch
              v-model="listQuery.isChildUser"
              active-color="var(--colorA1)"
              active-value="1"
              inactive-value="2"
            ></el-switch>
          </p> -->
					<el-tree
						:data="companyTableData"
						:props="defaultProps"
						:expand-on-click-node="false"
						accordion
						node-key="id"
						style="width: 260px; height: 630px; overflow-x: auto"
						@node-click="handleNodeClickDep1"
						:default-expanded-keys="expandedArr"
					></el-tree>
				</div>
			</el-aside>
			<el-main style="padding: 0 0 20px 20px" v-loading="loading">
				<el-table ref="multipleTable" :data="userTableData" style="width: 100%" :height="wrapHeight" stripe>
					<el-table-column type="selection" width="55"></el-table-column>
					<el-table-column fixed prop="userName" label="用户" width="200">
						<template slot-scope="scope">{{ scope.row | showUserInfo }}</template>
					</el-table-column>

					<el-table-column prop="deptFullName" label="部门" show-overflow-tooltip>
						<template slot-scope="scope">
							{{ scope.row.deptFullName | deptFormat }}
						</template>
					</el-table-column>
					<el-table-column prop="roleString" label="角色" show-overflow-tooltip></el-table-column>

					<el-table-column prop="del" label="状态" width="60px">
						<template slot-scope="{ row }">
							<span class="color-success" v-show="row.del == 1">可用</span>
							<span class="color-danger" v-show="row.del == 2">禁用</span>
						</template>
					</el-table-column>
					<el-table-column prop="createTime" label="创建时间" width="180px"></el-table-column>
					<el-table-column label="操作" width="120px">
						<template slot-scope="{ row }">
							<el-dropdown split-button type="primary" size="small">
								<span @click="showEditDialog('edit', row)">编辑</span>
								<el-dropdown-menu slot="dropdown">
									<el-dropdown-item v-if="row.del != '2' && row.id != 1" @click.native="ban(row)">封禁</el-dropdown-item>
									<el-dropdown-item v-if="row.del == '2' && row.id != 1" @click.native="activation(row)">激活</el-dropdown-item>
									<el-dropdown-item :disabled="$button('745') == false ? true : false" v-if="row.id != 1" @click.native="delUser(row)">
										删除
									</el-dropdown-item>
									<el-dropdown-item :disabled="$button('747') == false ? true : false" @click.native="resettingUser(row)">
										重置密码
									</el-dropdown-item>
								</el-dropdown-menu>
							</el-dropdown>
							<el-button-group v-show="false">
								<!-- <el-button
                type="primary"
                size="mini"
                @click="showEditDiskSize(row)"
                class="jurisdiction"
               
                >设置磁盘空间</el-button
                >-->
								<el-button
									type="primary"
									size="mini"
									@click="showEditDialog('edit', row)"
									class="jurisdiction"
									:disabled="$button('744') == false ? true : false"
								>
									编辑
								</el-button>
								<el-button
									type="danger"
									size="mini"
									@click="delUser(row)"
									class="jurisdiction"
									:disabled="$button('745') == false ? true : false"
								>
									删除
								</el-button>
								<!-- <el-button type="warning" size="mini" @click="configRole(row)">配置角色</el-button> -->
								<!-- <el-button
                  type="danger"
                  size="mini"
                  @click="ban(row)"
                  class="jurisdiction"
                  v-if="row.del != '2'"
                  :disabled="$button('746') == false ? true : false"
                  >封禁</el-button
                >
                <el-button
                  type="primary"
                  size="mini"
                  @click="activation(row)"
                  class="jurisdiction"
                  :disabled="$button('746') == false ? true : false"
                  v-if="row.del == '2'"
                  >激活</el-button
                > -->
								<el-button type="warning" size="mini" :disabled="$button('747') == false ? true : false" @click="resettingUser(row)">
									重置密码
								</el-button>
							</el-button-group>
						</template>
					</el-table-column>
				</el-table>
				<Pagination
					style="margin-top: 20px"
					v-show="parseInt(pageObj.count) > 0"
					:total="parseInt(pageObj.count)"
					@change="getList"
					:page.sync="listQuery.page"
					:limit.sync="listQuery.limit"
				/>
			</el-main>
		</el-container>

		<el-dialog :title="'角色配置'" :visible.sync="roleConfigVisible" :close-on-click-modal="false" width="600px" @close="$reset('rtemp')">
			<el-form ref="rtemp" label-width="80px">
				<el-form-item label="选择角色">
					<el-select style="width: 100%" v-model="checkList" multiple placeholder="请选择角色">
						<el-option v-for="(v, i) in roleTableData" :key="i" :label="v.key" :value="v.value"></el-option>
					</el-select>
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button type="custom" v-preventReClick @click="configUserSave">提 交</el-button>
				<el-button @click="roleConfigVisible = false">取 消</el-button>
			</div>
		</el-dialog>

		<el-dialog :title="'资源权限配置'" :visible.sync="levelConfigVisible" :close-on-click-modal="false" width="600px" @close="$reset('rtemp')">
			<el-form ref="rtemp" label-width="80px">
				<el-form-item label="资源权限" prop="level">
					<el-select v-model="levels" filterable placeholder="请选择资源权限">
						<el-option v-for="item in levelData" :key="item.value" :label="item.deName" :value="item.deValue">
							<span style="float: left">{{ item.deName }}</span>
							<span style="float: right; color: #8492a6; font-size: 12px">{{ item.content }}</span>
						</el-option>
					</el-select>
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button type="custom" v-preventReClick @click="configlevelSave">提 交</el-button>
				<el-button @click="levelConfigVisible = false">取 消</el-button>
			</div>
		</el-dialog>

		<el-dialog :title="'部门配置'" :visible.sync="deptConfigVisible" :close-on-click-modal="false" width="600px" @close="$reset('dtemp')">
			<el-form ref="dtemp" label-width="80px">
				<el-form-item label="选择部门">
					<el-popover placement="bottom-start" v-model="treeFlag2" class="orgTree" trigger="click">
						<el-tree
							:data="companyTableData"
							:props="defaultProps"
							:expand-on-click-node="false"
							node-key="id"
							style="width: 300px"
							@node-click="handleNodeClickDep2"
							ref="tree"
						></el-tree>
						<el-input
							slot="reference"
							ref="input"
							v-model="treeName2"
							clearable
							:readonly="true"
							style="width: 100%"
							placeholder="请选择部门"
						></el-input>
					</el-popover>
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button type="custom" v-preventReClick @click="configDeptSave">提 交</el-button>
				<el-button @click="deptConfigVisible = false">取 消</el-button>
			</div>
		</el-dialog>

		<!-- <el-dialog
      :title="'设置磁盘空间大小'"
      :visible.sync="dialogFormDiskSizeVisible"
      :close-on-click-modal="false"
      width="700px"
      @close="$reset('dstemp')"
    >
      <el-form ref="dstemp" label-width="80px">
        <el-form-item label="磁盘空间">
          <el-input
            v-model="dstemp.diskSpace"
            placeholder="请输入磁盘空间大小"
            type="number"
          ></el-input>
          <p style="color: red; margin-left: 5px">提示：磁盘空间大小单位为G</p>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="custom" v-preventReClick @click="configDiskSize"
          >提 交</el-button
        >
        <el-button @click="dialogFormDiskSizeVisible = false">取 消</el-button>
      </div>
    </el-dialog> -->
	</div>
</template>
<script>
import axios from 'axios';
import {
	tbSysUserQuery,
	tbUserAdd,
	tbUserUpdate,
	tbUserVali,
	tbUserAddBatch,
	tbUserBatchBanAndRecovery,
	tbUserDelete,
	tbUserImport,
	tbUserBatchUpdateDept,
	tbSysUserBatchUpdateLevel,
	tbUserUpdateDiskSize,
	tbSysUserBatchUpdatePassword
} from '@/api/admin/user/user-manage.js';
import { tbRoleQuery } from '@/api/admin/system/role.js';
import { tbDeptQuery } from '@/api/admin/user/department-manage.js';
import { tbDictDefinitionQueryEnumList, tbDictDefinitionQueryConstantStrList } from '@/api/admin/system/dictionary';
import { mapGetters } from 'vuex';
export default {
	components: {
		// ImportButtons: () => import('@/components/importButtons'),
	},
	computed: {
		...mapGetters(['userType']),
		wrapHeight() {
			let wHeight = document.body.clientHeight;
			let topDistance = 233;
			let h = wHeight - topDistance - 110;
			return h > 573 ? 573 : h;
		}
	},
	created() {
		this.$nextTick(() => {
			this.$refs.multipleTable.doLayout();
		});
		this.queryUserLevel();
		this.queryUserType();
		this.getList(true);
		this.getRoleList();
		this.getDeptList();
		this.getTbDictDefinitionQueryConstantStrList();
	},
	data() {
		// 重复密码验证
		const pwdAgainCheck = async (rule, value, callback) => {
			//这样才能在回调里通过箭头函数获取到this对象
			if (value != this.temp.password) {
				callback(new Error('与密码不一致'));
			} else {
				//校验通过
				callback();
			}
		};
		return {
			loading: false,
			width: `${document.documentElement.clientWidth}`,
			temp: { isLeader: '1' },
			dstemp: { diskSpace: '50' },
			checkList: [],
			roleTableData: [],
			levelData: [],
			levels: undefined,
			typeData: [],
			fileList: [],
			delData: [
				{ value: '1', label: '可用' },
				{ value: '2', label: '不可用' }
			],
			configRoleList: [],
			configDeptList: [],
			isReduce: true,
			isSelect: false,
			addOrEdit: true,
			radio: '1',
			passwordShow: true,
			jurisdictionType: '1',
			userPassword: '',
			listQuery: {
				page: 1,
				limit: 10,
				userName: '',
				education: '',
				account: '',
				del: 1,
				isChildUser: '1'
			},
			defaultProps: {
				children: 'childList',
				label: 'name'
			},
			userTableData: [],
			companyTableData: [],
			dialogVisible: false,
			dialogFormVisible: false,
			roleConfigVisible: false,
			levelConfigVisible: false,
			deptConfigVisible: false,
			fileUploadVisible: false,
			pageObj: {},
			treeFlag: false,
			treeFlag1: false,
			treeFlag2: false,
			treeName: '',
			treeName1: '',
			treeName2: '',
			deptIds: '',
			passwordTips: '请输入密码',
			passwordTips2: '请输入确认密码',
			fileTemp: '',
			dialogFormDiskSizeVisible: false, //设置磁盘空间大小弹出框
			options: [
				{
					value: '1',
					label: '博士'
				},
				{
					value: '2',
					label: '硕士'
				},
				{
					value: '3',
					label: '本科'
				},
				{
					value: '4',
					label: '大专'
				},
				{
					value: '5',
					label: '高中'
				}
			],
			expandedArr: []
		};
	},
	methods: {
		//查询用户等级
		async queryUserLevel() {
			let res = await this.$store.dispatch('queryOpenApiTbDictDetailByCode', 'TB_SYS_USER_LEVEL');
			this.levelData = res;
		},
		//查询用户类型
		queryUserType() {
			tbDictDefinitionQueryEnumList({ code: 'TB_SYS_USER_TYPE' }).then((res) => {
				let arr = [];
				for (let obj of res.data.data) {
					let list = {};
					list['label'] = obj.msg;
					list['value'] = obj.value;
					arr.push(list);
				}
				this.typeData = arr;
			});
		},
		//模板下载
		tempDownload() {
			window.location.href = this.baseURL + '/tbSysUser/down';
			//tbSysPersonnelTempDownload();
		},
		// 清空单位
		closeName() {
			this.treeName = '';
		},
		getTbDictDefinitionQueryConstantStrList() {
			tbDictDefinitionQueryConstantStrList({ code: 'USER_PASSWORD' }).then((res) => {
				this.userPassword = res.data.data[0];
			});
		},
		//验证账号是否存在
		VerifyAccountNumber() {
			tbUserVali({ account: this.temp.account, id: this.temp.id }).then((res) => {
				if (res.data.msg === '0') {
					this.handleAdd('temp');
				} else {
					this.$message({
						message: '账号已存在',
						type: 'error'
					});
				}
			});
		},

		// 选中上一级单位
		handleNodeClickDep(val) {
			this.treeName = val.name;
			this.treeFlag = false;
			this.temp.deptId = val.id;
		},
		// 选中上一级单位
		handleNodeClickDep1(val) {
			this.treeName1 = val.name;
			this.treeFlag1 = false;
			this.listQuery.deptId = val.id;
			this.getList();
		},
		// 选中上一级单位
		handleNodeClickDep2(val) {
			this.treeName2 = val.name;
			this.treeFlag2 = false;
			this.deptIds = val.id;
		},
		//查询所有
		getList(flag) {
			if (flag) {
				let { userId, userType, deptId, deptFullData } = this.$store.getters;
				if (userType == 1) {
					this.listQuery.deptId = '';
				} else {
					if (deptId) {
						this.listQuery.deptId = deptId;
					} else if (deptFullData.hasOwnProperty('childList') && deptFullData.childList.length) {
						let schoolDept = deptFullData.childList[0].id;
						this.listQuery.deptId = schoolDept;
					}
				}
			}
			this.loading = true;
			let listQuery = this.getSession('listQuery');
			if (listQuery) {
				let { page, limit } = JSON.parse(listQuery);
				this.listQuery.page = page || 1;
				this.listQuery.limit = limit || 10;
				this.removeSession('listQuery');
			}
			tbSysUserQuery(this.listQuery).then((res) => {
				for (let arr of res.data.data) {
					if (arr.hasOwnProperty('userRoleId')) {
						arr.userRoleId = arr.userRoleId.split(',');
					}
					let roleString = '';
					for (let menuObj of arr.menuRoleList) {
						roleString = roleString + menuObj.name + ',';
					}
					for (let powerObj of arr.powerRoleList) {
						roleString = roleString + powerObj.name + ',';
					}
					arr.roleString = roleString.slice(0, roleString.length - 1);
				}
				this.userTableData = res.data.data;
				this.pageObj = res.data;
				this.$refs.multipleTable.doLayout();
				let timer = setTimeout(() => {
					this.loading = false;
					clearTimeout(timer);
				}, 300);
			});
		},
		//切换菜单或者权限
		clickMenu() {
			this.checkList = '';
			this.temp.roleIds = '';
			this.getRoleList();
		},
		//查询所有角色
		getRoleList() {
			let data = {
				page: 1,
				limit: 9999,
				type: 1
			};
			//{type:this.jurisdictionType}只查询菜单角色
			tbRoleQuery(data).then((res) => {
				let arr = [];
				for (let role of res.data.data) {
					let list = {};
					//这里需要的是id
					list['key'] = role.name;
					list['value'] = role.id;
					arr.push(list);
				}
				this.roleTableData = arr;
			});
		},
		//查询部门
		getDeptList() {
			tbDeptQuery({ pId: '0' }).then((res) => {
				// console.log(res);
				// let { data } = res.data
				// let { userId, userType, deptFullData } = this.$store.getters
				// if (userType == 1) {
				//   //超管
				//   this.companyTableData = data
				// } else {
				//   //普通管理员
				//   if (!data.length || data.hasOwnProperty('childList')) return
				//   let fullDept = data[0].childList
				//   if (
				//     deptFullData.hasOwnProperty('childList') &&
				//     deptFullData.childList.length
				//   ) {
				//     let schoolDept = deptFullData.childList[0].id
				//     this.companyTableData = fullDept.filter((v) => v.id == schoolDept)
				//   }
				// }
				this.companyTableData = res.data.data;
				if (this.companyTableData.length) {
					this.expandedArr.push(this.companyTableData[0].id);
				}
				// this.companyTableData = res.data.data;
				// console.log(this.companyTableData);
			});
		},
		//删除
		delUser(row) {
			this.temp = { ...row };
			this.$confirm('删除人员将严重影响平台功能, 是否删除?', '提示', {
				confirmButtonText: '删除',
				cancelButtonText: '取消',
				type: 'warning'
			})
				.then(() => {
					let arr = [];
					let obj = {
						id: this.temp.id,
						list: this.temp
					};
					arr.push(obj);
					tbUserDelete(arr).then((res) => {
						if (res.data.code == 0) {
							this.$message({
								message: res.data.msg,
								type: 'success'
							});
						} else {
							this.$message({
								message: res.data.msg,
								type: 'error'
							});
						}
						this.dialogVisible = false;
						this.getList();
					});
				})
				.catch(() => {
					this.$message({
						type: 'info',
						message: '已取消删除'
					});
				});
		},
		//查询所有部门
		getDeptLsit() {
			tbDeptTreeList().then((res) => {
				this.deptData = res.data.data;
			});
		},
		//修改一条用户信息对应的磁盘空间-显示弹窗
		// showEditDiskSize(row) {
		//   var data = { ...row }
		//   this.dstemp.id = data.id
		//   this.dstemp.diskSpace = parseInt(data.diskSpaceStr)
		//   this.dialogFormDiskSizeVisible = true
		// },
		//修改一条用户信息对应的磁盘空间-提交接口
		configDiskSize() {
			tbUserUpdateDiskSize(this.dstemp).then((res) => {
				this.getList();
				this.dialogFormDiskSizeVisible = false;
			});
		},
		//新增/编辑弹框
		showEditDialog(type, row) {
			this.setSession('listQuery', JSON.stringify(this.listQuery));
			let data = {
				type: type,
				row: row
			};
			//  this.$store.commit("USEREDITDATA", data);
			this.$router.push({
				name: 'user-edit',
				params: { id: row ? row.id : '', type: type },
				query: { id: row ? row.id : '', type: type }
			});
		},
		ban(row) {
			this.$confirm('是否封禁此用户?', '提示', {
				confirmButtonText: '封禁',
				cancelButtonText: '取消',
				type: 'warning'
			})
				.then(() => {
					let obj = { id: row.id, del: '2' };
					let arr = [];
					arr.push(obj);
					tbUserBatchBanAndRecovery(arr).then((res) => {
						if (res.data.code == 0) {
							this.$message({
								message: res.data.msg,
								type: 'success'
							});
						} else {
							this.$message({
								message: res.data.msg,
								type: 'error'
							});
						}
						this.getList();
					});
				})
				.catch(() => {
					this.$message({
						type: 'info',
						message: '已取消封禁'
					});
				});
		},
		activation(row) {
			this.$confirm('是否激活此用户?', '提示', {
				confirmButtonText: '激活',
				cancelButtonText: '取消',
				type: 'warning'
			})
				.then(() => {
					let obj = { id: row.id, del: '1' };
					let arr = [];
					arr.push(obj);
					tbUserBatchBanAndRecovery(arr).then((res) => {
						if (res.data.code == 0) {
							this.$message({
								message: res.data.msg,
								type: 'success'
							});
						} else {
							this.$message({
								message: res.data.msg,
								type: 'error'
							});
						}
						this.getList();
					});
				})
				.catch(() => {
					this.$message({
						type: 'info',
						message: '已取消激活'
					});
				});
		},
		//更换角色类型
		replacementType() {},
		//数据导出
		dataExport() {
			let arr = this.$refs.multipleTable.selection;
			if (arr.length == 0) {
				window.location.href = this.baseURL + '/tbSysUser/export?account=' + this.listQuery.account + '&userName=' + this.listQuery.userName;
			} else {
				let url = this.baseURL + '/tbSysUser/export?id=';
				let ids = '';
				for (let obj of arr) {
					ids = ids + "'" + obj.id + "',";
				}
				window.location.href = url + ids.slice(0, ids.length - 1);
			}
		},
		//点击批量配置角色按钮
		configRoles() {
			this.configRoleList = [];
			this.configRoleList = this.$refs.multipleTable.selection;
			this.roleConfigVisible = this.configRoleList.length > 0;
			if (!this.roleConfigVisible) {
				this.$message({
					message: '请先选择用户',
					type: 'error'
				});
			}
		},
		//批量配置资源权限
		configLevel() {
			this.configRoleList = [];
			this.configRoleList = this.$refs.multipleTable.selection;
			this.levelConfigVisible = this.configRoleList.length > 0;
			if (!this.levelConfigVisible) {
				this.$message({
					message: '请先选择用户',
					type: 'error'
				});
			}
		},
		configDepts() {
			this.configDeptList = [];
			this.configDeptList = this.$refs.multipleTable.selection;
			this.deptConfigVisible = this.configDeptList.length > 0;
			if (!this.deptConfigVisible) {
				this.$message({
					message: '请先选择用户',
					type: 'error'
				});
			}
		},
		configDeptSave() {
			let arr = [];
			for (let des of this.configDeptList) {
				let obj = { id: des.id, deptId: this.deptIds };
				arr.push(obj);
			}

			tbUserBatchUpdateDept(arr).then((res) => {
				if (res.data.code == 0) {
					this.$message({
						message: res.data.msg,
						type: 'success'
					});
					this.deptConfigVisible = false;
					this.deptIds = [];
					this.getList();
				} else {
					this.$message({
						message: res.data.msg,
						type: 'error'
					});
				}
			});
		},

		//单个配置
		configRole(row) {
			this.configRoleList = [];
			let arr = [];
			arr.push(row);
			this.roleConfigVisible = true;
			this.configRoleList = arr;
		},
		configUserSave() {
			let arr = [];
			for (let ros of this.configRoleList) {
				for (let i = 0; i < this.checkList.length; i++) {
					let obj = { userId: ros.id, roleId: this.checkList[i] };
					arr.push(obj);
				}
			}
			tbUserAddBatch(arr).then((res) => {
				if (res.data.code == 0) {
					this.$message({
						message: res.data.msg,
						type: 'success'
					});
					this.roleConfigVisible = false;
					this.checkList = [];
					this.getList();
				} else {
					this.$message({
						message: res.data.msg,
						type: 'error'
					});
				}
			});
		},
		configlevelSave() {
			let arr = [];
			for (let ros of this.configRoleList) {
				let obj = { id: ros.id, level: this.levels };
				arr.push(obj);
			}
			tbSysUserBatchUpdateLevel(arr).then((res) => {
				if (res.data.code == 0) {
					this.$message({
						message: res.data.msg,
						type: 'success'
					});
					this.levelConfigVisible = false;
					this.checkList = [];
					this.getList();
				} else {
					this.$message({
						message: res.data.msg,
						type: 'error'
					});
				}
			});
		},
		//重置账号密码
		resettingUser(row) {
			this.temp = { ...row };
			this.$confirm('重置账号将初始化账号密码, 是否重置?', '提示', {
				confirmButtonText: '重置',
				cancelButtonText: '取消',
				type: 'warning'
			})
				.then(() => {
					var list = [{ id: this.temp.id, password: this.userPassword }];
					tbSysUserBatchUpdatePassword(list).then((res) => {
						if (res.data.code == 0) {
							this.$message({
								message: res.data.msg,
								type: 'success'
							});
						} else {
							this.$message({
								message: res.data.msg,
								type: 'error'
							});
						}
					});
				})
				.catch(() => {
					this.$message({
						type: 'info',
						message: '已取消重置'
					});
				});
		},
		//文件导入
		fileImport() {
			let formdata = new FormData();
			formdata.append('file', this.fileTemp);
			tbUserImport(formdata).then((res) => {
				if (res.data.data.length > 0) {
					if (res.data.data[0].errorData.length > 0) {
						this.$message.error(res.data.data[0].errorData[0]);
					} else {
						this.$message.success('导入成功');
					}
				} else {
					this.$message.success('导入成功');
				}
			});
		},
		handleChange(file, fileList) {
			this.fileTemp = file.raw;
		},
		handleRemove(file, fileList) {
			this.fileTemp = null;
		},
		handlePreview(file) {},
		handleExceed(files, fileList) {
			this.$message.warning('当前限制选择 1 个文件，请删除后继续上传');
		},
		//用户点击更多操作
		handleCommand(command) {
			switch (command) {
				case '1':
					this.showEditDialog('add');
					break;
				case '2':
					this.$refs.import.$el.click();
					break;
				case '3':
					this.configRole();
					break;
				default:
					break;
			}
		},
		//学历
		setFilterEducation(val) {
			var name = '';
			switch (val) {
				case '1':
					name = '博士';
					break;
				case '2':
					name = '硕士';
					break;
				case '3':
					name = '本科';
					break;
				case '4':
					name = '大专';
					break;
				case '5':
					name = '高中';
					break;
				default:
					name = val;
					break;
			}
			return name;
		},
		//选择角色后触发
		selectRoles() {
			let _this = this;
			setTimeout(function () {
				_this.$refs.selectAppType.blur();
			}, 50);
		},
		setType(id) {
			var name = '';
			this.typeData.forEach((ele) => {
				if (ele.value == id) {
					name = ele.label;
				}
			});
			return name;
		},

		// 清空上一级部门
		closeName1() {
			this.treeName1 = '';
			this.treeFlag1 = false;
			this.listQuery.deptId = '';
		}
	},
	mounted() {
		const _this = this;
		window.onresize = () => {
			return (() => {
				_this.width = `${document.documentElement.clientWidth}`;
			})();
		};
		this.$bus.$on('refreshUserList', () => {
			this.getList();
		});
	},
	beforeDestroy() {
		this.$bus.$off('refreshUserList');
	},
	watch: {
		//监测浏览器宽度对按钮做出改变
		width(val) {
			if (!this.timer) {
				this.width = val;
				this.timer = true;
				let _this = this;
				setTimeout(function () {
					_this.timer = false;
				}, 500);
			}
			// 这里可以添加修改时的方法
			if (val < 1812) {
				this.isReduce = false;
			} else {
				this.isReduce = true;
			}
		},
		//监听是修改还是新增的  改变密码框的提示
		addOrEdit(val) {
			if (val) {
				this.passwordTips = '请输入密码';
				this.passwordTips2 = '请再次输入密码';
			} else {
				this.passwordTips = '如果不需要修改密码，则无需填写';
				this.passwordTips2 = '如果不需要修改密码，则无需填写';
			}
		}
	}
};
</script>
<style scoped>
.el-col-24 {
	width: auto;
	/* padding-left: 3px !important; 
  padding-right: 3px !important; */
}
form.el-form .el-col.el-col-24 {
	width: 100%;
}
.el-col-lg-5 {
	width: 16.83333%;
}
.sea-span {
	width: 20%;
}
.sea-input {
	width: 70%;
	margin-left: 10px;
}
#personnel .aside-wrap {
	padding: 10px 10px 10px 10px;
	background: #f5f7fa;
}
.aside-title {
	padding: 5px 0;
}
</style>
<style>
#personnel .top_unit i.el-icon-circle-close,
.top_unit i.el-icon-arrow-down {
	position: absolute;
	right: 18px;
	top: 13px;
	cursor: pointer;
	color: #c2cadb;
}
</style>
<style>
.left-menu {
	display: block;
}
#personnel .el-table--border th.gutter:last-of-type {
	display: table-cell !important;
	width: 50px !important;
}
#personnel .el-tree-node__content {
	height: 30px;
}
</style>
